package com.gzdh.dishrecognition.ui.dialog.identify;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dhkj.web.idf.IdfRequestUtils;
import com.dhkj.web.idf.IdfTagRequestUtils;
import com.dhkj.web.idf.model.ActiveWraper;
import com.dhkj.web.idf.model.DeviceLogin;
import com.dhkj.web.idf.model.DeviceLoginWraper;
import com.dhkj.web.idf.model.Merchant;
import com.dhkj.web.idf.model.MerchantWraper;
import com.dhkj.web.utils.MyObserverNo;
import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.util.AssetUtils;
import com.gzdh.dishrecognition.util.SdcardUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class RegIdentifyDialog extends Dialog {
    private Context mContext;
    private Activity mActivity;
    private Window window = null;
    private EditText activeCodeEd;
    private EditText activeExpiryDateEd;
    private EditText activeDeviceNumberEd;
    private EditText activeStatusEd;
    private EditText activeSoftModeEd;
    private TextView activeMerchantBut;
    private EditText activeDeviceNameEd;
    private Button activeButton;
    private Button reactiveBtn;
    private List<Merchant> merchantList;

    public void initActive() {
        activeStatusEd.setText("未激活");
        activeButton.setEnabled(true);
        activeMerchantBut.setEnabled(true);
        activeDeviceNameEd.setBackgroundResource(R.drawable.rounded_text);
        activeDeviceNameEd.setEnabled(true);
    }

    public void initActived() {
        activeStatusEd.setText("已激活");
        activeButton.setEnabled(false);
        activeMerchantBut.setEnabled(false);
        activeDeviceNameEd.setBackground(null);
        activeDeviceNameEd.setEnabled(false);
    }

    public RegIdentifyDialog(@NonNull Activity context) {
        super(context, R.style.CustomDialog);
        mActivity = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this.getContext();
        View view = getView();
        setContentView(view);

        //点击dialog以外的空白处是否隐藏
//        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();
        //设置窗口显示
        windowDeploy();
    }

    private void initView() {

    }

    private void initData() {
        IdfRequestUtils.registrationQuery(mContext, new MyObserverNo<ActiveWraper>(mContext, false) {
            @Override
            public void onSuccess(ActiveWraper result) {
                System.out.println("请求成功" + result.toString());
                if (result.getState() == 0) {
                    if (TextUtils.isEmpty(result.getActive().getCode())) {
                        activeStatusEd.setText("未激活");
                    } else {
                        activeStatusEd.setText("已激活");
                        activeExpiryDateEd.setText(result.getActive().getExpiryDate());
                        activeCodeEd.setText(result.getActive().getCode());
                        activeDeviceNumberEd.setText(String.valueOf(result.getActive().getDeviceNumber()));

                        try {
                            JSONArray jsonArray = new JSONArray(AssetUtils.resdJsonString(mContext, "softmode.json"));
                            int softmode = (result.getActive().getCode() != null
                                    && result.getActive().getCode().length() > 2) ?
                                    Integer.parseInt(result.getActive().getCode().substring(0, 2)) : 0;
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                if (softmode == jsonObject.getInt("key")) {
                                    activeSoftModeEd.setText(jsonObject.getString("value"));
                                    break;
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        listMerchant();
                    }


                }
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                activeStatusEd.setText("识别服务器连接异常");
            }
        });
    }

    private void listMerchant() {
        IdfTagRequestUtils.listMerchant(mContext, new MyObserverNo<MerchantWraper>(mContext, false) {
            @Override
            public void onSuccess(MerchantWraper result) {
                merchantList = result.getMerchants();
                deviceLogin();
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {

            }
        });
    }

    private void deviceLogin() {
        String registrationNumber = SdcardUtils.getRegistrationNumber();
        IdfTagRequestUtils.deviceLogin(mContext, registrationNumber, new MyObserverNo<DeviceLoginWraper>(mContext, false) {
            @Override
            public void onSuccess(DeviceLoginWraper result) {
                DeviceLogin deviceLogin = result.getResult();
                String merchantName = "";
                List<String> mItems = new ArrayList<>();
                int index = 0;
                for (int i = 0; i < merchantList.size(); i++) {
                    Merchant merchant = merchantList.get(i);
                    mItems.add(merchant.getMerchantName());
                    if (deviceLogin != null && merchant.getMerchantPK() == deviceLogin.getMerchantPK()) {
                        index = i;
                        merchantName = merchant.getMerchantName();
                    }
                }

//                ArrayAdapter<String> recognitionAdapter = new ArrayAdapter<>(getActivity(), R.layout.my_simple_item, mItems);
//                active_merchant.setAdapter(recognitionAdapter);
//                active_merchant.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
//                    @Override
//                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//                        merchant = merchants.get(position);
//                    }
//
//                    @Override
//                    public void onNothingSelected(AdapterView<?> parent) {
//
//                    }
//                });

                activeMerchantBut.setText(merchantName);
                if (result.getState() == 200) {
                    if (result.getResult() != null)
                        activeDeviceNameEd.setText(deviceLogin == null ? "" : deviceLogin.getDeviceName());
                    initActived();
                } else if (result.getState() == 620 || 400 == result.getState()) {
                    initActive();
                }
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {

            }
        });

    }

    private void initEvent() {
        reactiveBtn.setOnClickListener(view -> {
            initActive();
        });
        activeMerchantBut.setOnClickListener(view -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
            builder.setTitle("所属商户");
            final Map<String, Integer> map = new LinkedHashMap<>();
            for (int i = 0; i < merchantList.size(); i++) {
                Merchant merchant = merchantList.get(i);
                map.put(merchant.getMerchantName(), merchant.getMerchantPK());

            }
            final String[] keysTemp = new String[merchantList.size()];
            final String[] keys = map.keySet().toArray(keysTemp);
            builder.setItems(keys, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int state = map.get(keys[which]);
//                    SysConstConfig.getInstance().setHideDinner(state);
//                    showState();
                }
            });
            builder.show();
        });
    }

    private void windowDeploy() {
        window = getWindow();
        window.setGravity(Gravity.CENTER); //设置窗口显示位置
//        window.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
    }


    private View getView() {
        RelativeLayout mainRv = new RelativeLayout(mContext);
        mainRv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        mainRv.setBackgroundColor(Color.WHITE);

        RelativeLayout titleLayout = new RelativeLayout(mContext);
        titleLayout.setId(View.generateViewId());
        titleLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 70));
        mainRv.addView(titleLayout);

        TextView titleTv = new TextView(mContext);
        titleTv.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        titleTv.setText("设备激活");
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
        titleTv.setPadding(30, 20, 0, 0);
        titleTv.setTextColor(Color.BLACK);
        titleLayout.addView(titleTv);

        activeButton = new Button(mContext);
        RelativeLayout.LayoutParams rvParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        rvParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        rvParams.setMargins(0, 12, 30, 0);
        activeButton.setLayoutParams(rvParams);
        activeButton.setEnabled(false);
        activeButton.setText("激活");
        activeButton.setPadding(15, 10, 15, 10);
        activeButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        activeButton.setTextColor(Color.BLACK);
        titleLayout.addView(activeButton);

        View line = new View(mContext);
        rvParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
        rvParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        line.setLayoutParams(rvParams);
        line.setBackgroundColor(Color.rgb(224, 224, 224));
        titleLayout.addView(line);


        LinearLayout bodyLinear = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.BELOW, titleLayout.getId());
        bodyLinear.setLayoutParams(rvParams);
        bodyLinear.setOrientation(LinearLayout.VERTICAL);
        mainRv.addView(bodyLinear);

        //region 激活状态
        RelativeLayout relativeLayout = new RelativeLayout(mContext);
        LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
        linearParams.setMargins(0, 20, 0, 0);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        LinearLayout linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        TextView textView = new TextView(mContext);
        textView.setText("激活状态：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);

        activeStatusEd = new EditText(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        activeStatusEd.setLayoutParams(rvParams);
        activeStatusEd.setBackground(null);
        activeStatusEd.setEnabled(false);
        activeStatusEd.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeStatusEd.setPadding(5, 0, 5, 0);
        activeStatusEd.setSingleLine(true);
        activeStatusEd.setTextColor(Color.BLACK);
        activeStatusEd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        relativeLayout.addView(activeStatusEd);
        //endregion


        //region 激活码
        relativeLayout = new RelativeLayout(mContext);
        linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearParams.setMargins(0, 10, 0, 0);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        textView = new TextView(mContext);
        textView.setText("激活码：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);


        RelativeLayout codeLayout = new RelativeLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        codeLayout.setLayoutParams(rvParams);
        relativeLayout.addView(codeLayout);


        reactiveBtn = new Button(mContext);
        reactiveBtn.setId(View.generateViewId());
        rvParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        reactiveBtn.setLayoutParams(rvParams);
        reactiveBtn.setText("重新激活");
        codeLayout.addView(reactiveBtn);


        activeCodeEd = new EditText(mContext);
        rvParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        rvParams.setMargins(0, 0, 10, 0);
        rvParams.addRule(RelativeLayout.LEFT_OF, reactiveBtn.getId());

        activeCodeEd.setLayoutParams(rvParams);
        activeCodeEd.setHint("输入激活码");
        activeCodeEd.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeCodeEd.setSingleLine(true);
        activeCodeEd.setPadding(5, 5, 5, 5);
        codeLayout.addView(activeCodeEd);
        //endregion


        //region 有效时间
        relativeLayout = new RelativeLayout(mContext);
        linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearParams.setMargins(0, 10, 0, 0);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        textView = new TextView(mContext);
        textView.setText("有效时间：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);

        activeExpiryDateEd = new EditText(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        activeExpiryDateEd.setLayoutParams(rvParams);
        activeExpiryDateEd.setBackground(null);
        activeExpiryDateEd.setEnabled(false);
        activeExpiryDateEd.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeExpiryDateEd.setPadding(5, 0, 5, 0);
        activeExpiryDateEd.setSingleLine(true);
        activeExpiryDateEd.setTextColor(Color.BLACK);
        activeExpiryDateEd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        relativeLayout.addView(activeExpiryDateEd);
        //endregion

        //region 激活类型
        relativeLayout = new RelativeLayout(mContext);
        linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearParams.setMargins(0, 10, 0, 0);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        textView = new TextView(mContext);
        textView.setText("激活类型：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);

        activeSoftModeEd = new EditText(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        activeSoftModeEd.setLayoutParams(rvParams);
        activeSoftModeEd.setBackground(null);
        activeSoftModeEd.setEnabled(false);
        activeSoftModeEd.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeSoftModeEd.setPadding(5, 0, 5, 0);
        activeSoftModeEd.setSingleLine(true);
        activeSoftModeEd.setTextColor(Color.BLACK);
        activeSoftModeEd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        relativeLayout.addView(activeSoftModeEd);
        //endregion

        //region 激活数量
        relativeLayout = new RelativeLayout(mContext);
        linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearParams.setMargins(0, 10, 0, 0);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        textView = new TextView(mContext);
        textView.setText("激活数量：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);

        activeDeviceNumberEd = new EditText(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        activeDeviceNumberEd.setLayoutParams(rvParams);
        activeDeviceNumberEd.setBackground(null);
        activeDeviceNumberEd.setEnabled(false);
        activeDeviceNumberEd.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeDeviceNumberEd.setPadding(5, 0, 5, 0);
        activeDeviceNumberEd.setSingleLine(true);
        activeDeviceNumberEd.setTextColor(Color.BLACK);
        activeDeviceNumberEd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        relativeLayout.addView(activeDeviceNumberEd);
        //endregion


        //region 所属商户
        relativeLayout = new RelativeLayout(mContext);
        linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearParams.setMargins(0, 10, 0, 0);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        textView = new TextView(mContext);
        textView.setText("所属商户：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);

        activeMerchantBut = new TextView(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        activeMerchantBut.setLayoutParams(rvParams);
        activeMerchantBut.setBackground(null);
        activeMerchantBut.setEnabled(false);
        activeMerchantBut.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeMerchantBut.setPadding(5, 0, 5, 0);
        activeMerchantBut.setSingleLine(true);
        activeMerchantBut.setTextColor(Color.WHITE);
        activeMerchantBut.setGravity(Gravity.CENTER);
        activeMerchantBut.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        activeMerchantBut.setBackground(mContext.getResources().getDrawable(R.drawable.bg_btn_pay));
        relativeLayout.addView(activeMerchantBut);
        //endregion

        relativeLayout = new RelativeLayout(mContext);
        linearParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearParams.setMargins(0, 10, 0, 50);
        relativeLayout.setLayoutParams(linearParams);
        relativeLayout.setGravity(Gravity.CENTER);
        bodyLinear.addView(relativeLayout);

        linearLayout = new LinearLayout(mContext);
        rvParams = new RelativeLayout.LayoutParams(160, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_VERTICAL);
        linearLayout.setLayoutParams(rvParams);
        relativeLayout.addView(linearLayout);

        textView = new TextView(mContext);
        textView.setText("设备名称：");
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        linearLayout.addView(textView);

        activeDeviceNameEd = new EditText(mContext);
        rvParams = new RelativeLayout.LayoutParams(250, ViewGroup.LayoutParams.WRAP_CONTENT);
        rvParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        activeDeviceNameEd.setLayoutParams(rvParams);
        activeDeviceNameEd.setBackground(null);
        activeDeviceNameEd.setEnabled(false);
        activeDeviceNameEd.setImeOptions(EditorInfo.IME_ACTION_SEND);
        activeDeviceNameEd.setPadding(5, 0, 5, 0);
        activeDeviceNameEd.setSingleLine(true);
        activeDeviceNameEd.setTextColor(Color.BLACK);
        activeDeviceNameEd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        relativeLayout.addView(activeDeviceNameEd);
        return mainRv;
    }

}
